/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.geaSV.busquedas;

import com.geaSV.conexiones.conectarBD;
import com.geaSV.entities.DepartamentoE;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author vash
 */
public class busquedaDepartamento {
    private Connection conx=null;
    private Statement sttm; 
    private ResultSet rs;
    
    public List<DepartamentoE> obtenerDepartamentosTodos() throws SQLException{
        List <DepartamentoE> lst=new ArrayList<DepartamentoE> (0);
        try{
            conx= conectarBD.conectar();
            sttm= conx.createStatement();
            rs=sttm.executeQuery("SELECT * FROM departamento");
            while(rs.next()){
            DepartamentoE D=new DepartamentoE();
            D.setId(rs.getInt("id"));
            D.setNombre(rs.getString("nombre"));
            lst.add(D);
            }
        }catch(Exception e){
            System.out.println(e.getMessage());
            
        }finally{
            rs.close();
            sttm.close();
            conx.close();
            return lst;
        }
    }
}
